package sz.szsmk.citizencard.ui.activity;

import android.graphics.Rect;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chenenyu.router.annotation.Route;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.ui.adapter.BusChangeDetailAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;

@Route("BusChangeDetailActivity")
public class BusChangeDetailActivity extends IBaseActivity {
    TextView tv_baseinfo;
    TextView tv_taxiinfo;
    RecyclerView recycler;
    private BusChangeDetailAdapter adapter;
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_buschangdetail;
    }

    @Override
    protected void initInjector() {

    }

    class SpaceItemDecoration extends RecyclerView.ItemDecoration {
        int mSpace;

        /**
         * Retrieve any offsets for the given item. Each field of <code>outRect</code> specifies
         * the number of pixels that the item view should be inset by, similar to padding or margin.
         * The default implementation sets the bounds of outRect to 0 and returns.
         * <p>
         * <p>
         * If this ItemDecoration does not affect the positioning of item views, it should set
         * all four fields of <code>outRect</code> (left, top, right, bottom) to zero
         * before returning.
         * <p>
         * <p>
         * {@link RecyclerView#getChildAdapterPosition(View)} to get the adapter position of the
         * View.
         *
         * @param outRect Rect to receive the output.
         * @param view    The child view to decorate
         * @param parent  RecyclerView this ItemDecoration is decorating
         * @param state   The current state of RecyclerView.
         */
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.left = mSpace;
            outRect.right = mSpace;
            outRect.bottom = mSpace;
            if (parent.getChildAdapterPosition(view) == 0) {
                outRect.top = mSpace;
            }

        }

        public SpaceItemDecoration(int space) {
            this.mSpace = space;
        }
    }

    @Override
    protected void initViews() {

        tv_baseinfo = findViewById(R.id.baseinfo);
        tv_taxiinfo =  findViewById(R.id.taxiinfo);
        recycler =  findViewById(R.id.recycler);


        ImageView back = (ImageView) findViewById(R.id.back);
        TextView title = (TextView) findViewById(R.id.setting_title);
        title.setText("路线详情");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };

        recycler.setLayoutManager(mLayoutManager);
        recycler.addItemDecoration(new SpaceItemDecoration(0));
//        recycler.setNestedScrollingEnabled(false);
//        recycler.setHasFixedSize(true);
//        recycler.setFocusable(false);
        String time = getIntent().getStringExtra("time");
        String distance = getIntent().getStringExtra("diatance");
        tv_baseinfo.setText(time+"("+distance+")");
        recycler.setAdapter(adapter);
    }

    @Override
    protected void updateViews() {

    }


}
